
# 基本练习：
# 通过 id 属性定位页面中的【id】标签
# 通过 class 属性定位页面中的【class】标签

import time
from selenium import webdriver
from selenium.webdriver.common.by import By


def test_css_xpath():
  driver=webdriver.Chrome()
  driver.get("https://vip.ceshiren.com/#/ui_study/locate")
  time.sleep(3)
  #基本练习
  id_element=driver.find_element(By.ID,"located_id")
  print(id_element.text)
  class_name=driver.find_element(By.CLASS_NAME,"locate_class_name ")
  print(class_name.text)

  # 关系定位：
# 通过父子关系定位页面中的【father】标签

  father_son_relation=driver.find_element(By.XPATH,"//div[@class='grandfather']/div[@class='pos father']/button/span[text()='father']")
  print(father_son_relation.text)
# 顺序关系：
# 通过顺序关系定位到页面中的【sister】标签
 #app > div > section > section > main > div > div.box2 > div.grandfather > div.pos.father > div.sister
  sister_order=driver.find_element(By.CSS_SELECTOR,"div.grandfather>div.pos.father>div:nth-child(4)")
  print(sister_order.text)
 
if __name__ == '__main__':
  test_css_xpath()